package com.topc.problem.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.topc.base.exception.Asserts;
import com.topc.base.model.PageResult;
import com.topc.problem.mapper.ProblemDealContentMapper;
import com.topc.problem.model.po.ProblemDealCommentInfo;
import com.topc.problem.model.po.ProblemDealContent;
import com.topc.problem.service.IProblemDealContentService;
import org.springframework.stereotype.Service;
@Service
public class ProblemDealContentServiceImpl extends ServiceImpl<ProblemDealContentMapper, ProblemDealContent> implements IProblemDealContentService{
//    @Override
//    public Page<ProblemDealContent> searchByPage(int pageSize, int pageCurrent, ProblemDealContent problemDealContent) {
//        PageEntity pageEntity = new PageEntity(pageCurrent,pageSize);
//        LambdaQueryWrapper<ProblemDealContent> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//
//        if (!ObjectUtil.isEmpty(problemDealContent.getId())){
//            lambdaQueryWrapper.eq(ProblemDealContent::getId,problemDealContent.getId());
//        }
//        if (!ObjectUtil.isEmpty(problemDealContent.getStatus())){
//            lambdaQueryWrapper.eq(ProblemDealContent::getStatus,problemDealContent.getStatus());
//        }
//        return this.getBaseMapper().selectPage(pageEntity.toPage(),lambdaQueryWrapper);
//    }


    @Override
    public PageResult<ProblemDealCommentInfo> searchByPage(int pageSize, int pageCurrent, long dealId) {
        return null;
    }

    @Override
    public Long saveContentToId(String content) {
        ProblemDealContent dealContent = new ProblemDealContent();
        dealContent.setContent(content);
        boolean save = this.save(dealContent);
        if (!save) Asserts.fail("保存失败");
        return dealContent.getId();
    }

    @Override
    public void saveContentById(Long contentId, String content) {
        LambdaUpdateWrapper<ProblemDealContent> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(ProblemDealContent::getId, contentId);
        updateWrapper.set(ProblemDealContent::getContent,content);
        boolean update = this.update(updateWrapper);
        if (!update)Asserts.fail("内容更新失败");
    }

    @Override
    public void deleteInfoById(Long contentId) {
        LambdaQueryWrapper<ProblemDealContent> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ProblemDealContent::getId, contentId);
        boolean removeContent = this.remove(lambdaQueryWrapper);
        if (!removeContent)Asserts.fail("删除失败");
    }
}
